package dpda;

import org.junit.jupiter.api.Test;
import pda.PDARule;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author haoly
 * @title DPDADesignTest
 * @date 2025/4/21 14:43
 * @description TODO
 */
public class DPDADesignTest {
    @Test
    public void testAccepts() {
        List<PDARule<Integer>> rules = Arrays.asList(
                new PDARule<>(1, '(', 2, '$', "b$"),
                new PDARule<>(2, '(', 2, 'b', "bb"),
                new PDARule<>(2, ')', 2, 'b', ""),
                new PDARule<>(2, null, 1, '$', "$")
        );
        DPDARulebook<Integer> rulebook = new DPDARulebook<>(rules);
        DPDADesign<Integer> dpdaDesign = new DPDADesign<>(1, '$', Set.of(1), rulebook);
        assertTrue(dpdaDesign.accepts("(((((((((())))))))))"));
        assertTrue(dpdaDesign.accepts("()(())((()))(()(()))"));
        assertFalse(dpdaDesign.accepts("(()(()(()()(()()))()"));
        assertFalse(dpdaDesign.accepts("())"));
    }

    @Test
    public void testAccepts2() {
        List<PDARule<Integer>> rules = Arrays.asList(
                new PDARule<>(1, '(', 2, '$', "b$"),
                new PDARule<>(2, '(', 2, 'b', "bb"),
                new PDARule<>(2, ')', 2, 'b', ""),
                new PDARule<>(2, null, 1, '$', "$")
        );
        DPDARulebook<Integer> rulebook = new DPDARulebook<>(rules);
        DPDADesign<Integer> dpdaDesign = new DPDADesign<>(1, '$', Set.of(1), rulebook);
        assertFalse(dpdaDesign.accepts("())"));
    }
}
